﻿using System;
using System.Collections.Generic;
using System.Text;
using AdaptiveAgents.Tools;

namespace AdaptiveAgents.Formulas
{
    class FirstPartOfCheckingTool
    {
        private Record m_rMyRecord;
        private ProbabilitiesMatrix m_pmProbabilities;

        public FirstPartOfCheckingTool() { m_pmProbabilities = new ProbabilitiesMatrix(); }
        public FirstPartOfCheckingTool(Record rec) { m_rMyRecord = rec; m_pmProbabilities = new ProbabilitiesMatrix(); }
        public void setRecord(Record rec) { m_rMyRecord = rec; }
        public void clear() { m_rMyRecord = null; m_pmProbabilities = null; }
        public void reInstall(Record rec) { m_rMyRecord = rec; m_pmProbabilities = new ProbabilitiesMatrix(); }



        public void solve()
        {
            AgentInfo agent0 = new AgentInfo(0, m_rMyRecord.getEpsilon(0), m_rMyRecord.getCompetence(0), new ProbabilityCreatorSecondVersion(m_rMyRecord.getEpsilon(0)));
            AgentInfo agent1 = new AgentInfo(1, m_rMyRecord.getEpsilon(1), m_rMyRecord.getCompetence(1), new ProbabilityCreatorSecondVersion(m_rMyRecord.getEpsilon(1)));
            AgentInfo agent2 = new AgentInfo(2, m_rMyRecord.getEpsilon(2), m_rMyRecord.getCompetence(2), new ProbabilityCreatorSecondVersion(m_rMyRecord.getEpsilon(2)));
            
            int agentLevel0=0, agentLevel1=0, agentLevel2=0;

            agentLevel0 = AgentComperator.getAgentLevel(agent0, agent1, agent2);
            agentLevel1 = AgentComperator.getAgentLevel(agent1, agent0, agent2);
            agentLevel2 = AgentComperator.getAgentLevel(agent2, agent1, agent0);

            m_pmProbabilities.setProbability0to0(agent0.getEpsilonTo0(agentLevel0, agentLevel0));
            m_pmProbabilities.setProbability0to1(agent0.getEpsilonTo1(agentLevel0, agentLevel1));
            m_pmProbabilities.setProbability0to2(agent0.getEpsilonTo2(agentLevel0, agentLevel2));

            m_pmProbabilities.setProbability1to0(agent1.getEpsilonTo0(agentLevel1, agentLevel0));
            m_pmProbabilities.setProbability1to1(agent1.getEpsilonTo1(agentLevel1, agentLevel1));
            m_pmProbabilities.setProbability1to2(agent1.getEpsilonTo2(agentLevel1, agentLevel2));

            m_pmProbabilities.setProbability2to0(agent2.getEpsilonTo0(agentLevel2, agentLevel0));
            m_pmProbabilities.setProbability2to1(agent2.getEpsilonTo1(agentLevel2, agentLevel1));
            m_pmProbabilities.setProbability2to2(agent2.getEpsilonTo2(agentLevel2, agentLevel2));
        }

        public ProbabilitiesMatrix getSolution()
        {
            return m_pmProbabilities;
        }


    }
}
